<?php
class Admin_BannerController extends Zendvn_Controller_Action{
	
	//Mang tham so nhan duoc o moi Action
	protected $_arrParam;
	
	//Duong dan cua Controller
	protected $_currentController;
	
	//Duong dan cua Action chinh
	protected $_actionMain;
	
	//Thong so phan trang
	protected $_paginator = array(
									'itemCountPerPage' => 5,
									'pageRange' => 3,
								  ); 
	protected $_namespace;
	protected $_user;
	
	public function init(){
		//Mang tham so nhan duoc o moi Action
		$this->_arrParam = $this->_request->getParams();
		$template_path = TEMPLATE_PATH . "/admin";
		$this->loadTemplate($template_path,'template.ini','template');
		$this->view->active ="5";
		$this->_user = new Zend_Session_Namespace ( "user" );
		if (!isset ( $this->_user->username ) ||$this->_user->role!="0"){
			$this->_redirect ( "admin/" );
		}
		$this->view->active ="6";
		$this->view->username =$this->_user->username;
		$this->view->role =$this->_user->role;
		}

	public function indexAction(){
		$dataBase = new  Admin_Model_Banner();
		$pages=$dataBase->getAll();
		$pa = Zend_Paginator::factory($pages);
		$pa->setItemCountPerPage(4);// xet so hang tren mọt trang
		$pa->setPageRange(5);
		$current = $this->_request->getParam('page');
		$pa->setCurrentPageNumber($current);
		// phan trang cache du lieu
		$fO = array("lifetime"=>3600, "automatic_serialization"=>true);
		$bO = array("cache_dir"=> APPLICATION_PATH.'/../public/tmp');
		$cache = Zend_Cache::factory('Core', 'File', $fO,$bO);
		Zend_Paginator::setCache($cache);
		$this->view->pages=$pa;
	
	}
	public function addAction(){
		if($this->_request->isPost()){
			
				$pages = new Admin_Model_Banner();
				$pages->addBanner($this->_arrParam );
				
			
		}
	}
	public function editAction(){
		if($this->_request->isPost()){
			$pages = new Admin_Model_Banner();
			$pages->editBanner($this->_arrParam );
		}
		$pages = new Admin_Model_Banner();
		$banner =$pages->getBanner($this->_arrParam);
		$this->view->banner =$banner;
	}
	public function deleteAction(){
		$pages = new Admin_Model_Banner();
		$page["id"]=$this->_arrParam["id"];
		$pages->deleteBanner($page);
		$this->_redirect ( "admin/banner" );
	}
	
}
